﻿using System;
using System.IO;

namespace SourcesUnPacker
{
    public class RoleFrame
    {
        public int imageCount;

        public int[] imageType;

        public int[] imageTypeDraw;

        public RoleImage[][] images;

        public static RoleFrame read(BinaryReader reader)
        {
            var frame = new RoleFrame();

            frame.imageCount = reader.ReadInt32();
            // 读取ImageType
            // Console.WriteLine("imageCount: " + frame.imageCount);
            frame.imageType = new int[frame.imageCount];
            for (int i = 0; i < frame.imageCount; i++)
            {
                frame.imageType[i] = reader.ReadInt32();
            }

            //打印下所有的ImageType
            // Console.WriteLine("imageType: " + string.Join(",", frame.imageType));

            // 读取ImageTypeDraw
            frame.imageTypeDraw = new int[frame.imageCount];
            for (int i = 0; i < frame.imageCount; i++)
            {
                frame.imageTypeDraw[i] = reader.ReadInt32();
            }
            //打印imageTypeDraw
            // Console.WriteLine("imageTypeDraw: " + string.Join(",", frame.imageTypeDraw));
            
            // 读取Images
            frame.images = new RoleImage[frame.imageCount][];
            for (int i = 0; i < frame.imageCount; i++)
            {
                int count = reader.ReadInt32();
                frame.images[i] = new RoleImage[count];
                for (int j = 0; j < count; j++)
                {   
                    var image = RoleImage.read(reader);
                    // Console.WriteLine("image: "+image.ToString());
                    frame.images[i][j] =image; 
                }
            }
            return frame;
        }
    }
}